{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 安装mysql模块\n",
    "\n",
    "- pip install PyMySQL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入pandas 和 pymysql 包\n",
    "import pandas as pd\n",
    "import pymysql\n",
    "# 返回一个 Connection 对象\n",
    "db_conn = pymysql.connect(\n",
    "host='localhost',\n",
    "port=3306,\n",
    "user='root',\n",
    "password='****',\n",
    "database='example',\n",
    "charset='utf8'\n",
    ")\n",
    "print(db_conn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入pandas 和 pymysql 包\n",
    "import pandas as pd\n",
    "import pymysql\n",
    "# 返回一个 Connection 对象\n",
    "db_conn = pymysql.connect(\n",
    "host='localhost',\n",
    "port=3306,\n",
    "user='root',\n",
    "password='0508',\n",
    "database='example',\n",
    "charset='utf8'\n",
    ")\n",
    "\n",
    "# 执行sql操作\n",
    "sql=\"select * from t_file\"\n",
    "pd.read_sql(sql,con=db_conn)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.9.8 (tags/v3.9.8:bb3fdcf, Nov  5 2021, 20:48:33) [MSC v.1929 64 bit (AMD64)]"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "6fff98fc3b3d81bd655c2cc48858186e4d9e2db7b515bf1c3221888f12a62f87"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
